capture log close
log using "Y:\Documents\Output\robustness2_analysis", replace text

*************************************************************************
* do-file to run conditional logit models 								*
*	for supplementary analysis with additional sep.sphere variables		*
* fo 02.07.2015															*	
*************************************************************************

version 13
clear
set more off
cd "Y:\Documents\"
use "Data\data_choice_long.dta", clear
keep if sample_supl==1

*** Globals ***
global maineffects = "fach1-fach7 fach9-fach23" /* refcat: econ sciences */
global modnr = 21	/* number of models to be stored in matrix */

********************************************************
***		 multivariate analysis of effects		 ***
********************************************************
clogit choice $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	est sto a_m1
	esttab a_m1 using "Output\robustness2_directeffects.csv", replace b(a4) se eform

clogit choice $maineffects std_mathintxdoer std_carexdoer std_mathintxthinker std_carexthinker std_mathintxcreator std_carexcreator std_mathintxhelper std_carexhelper std_mathintxpersuader std_carexpersuader std_mathintxorganizer std_carexorganizer std_apfmeltxfrau std_apfmpeerxfrau std_mathintxleist_md std_intercptxbread std_intercptxbread2 std_intercptxbread4 std_intercptxbread4xfrau std_hrsworkxflexi std_hrsworkxbread3 std_hrsworkxbread3xfrau  std_sdiscrimxfrau [pw=w_t13_std], group(id_ind) or
	est sto a_m2
	esttab a_m2 using "Output\robustness2_directeffects.csv", append b(a4) se eform
	
*******************************************
***		 min max decomposition		***
*******************************************			

* reference models: baseline and saturated:
qui clogit choice pfemale2xfrau $maineffects 																																  																																	 																								[pw=w_t13_std], group(id_ind) or
	matrix A = (e(b))
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau  sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix B = e(b)
	
* 1 - interest: doer
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer 																																  																												 																										[pw=w_t13_std], group(id_ind) or
	matrix E1max = e(b)	
qui clogit choice pfemale2xfrau $maineffects 			  			mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau  sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E1min = e(b)
	
* 2 - interest: thinker
qui clogit choice pfemale2xfrau $maineffects  						mathintxthinker carexthinker																			  																																	 																											[pw=w_t13_std], group(id_ind) or
	matrix E2max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer 							 mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E2min = e(b)

* 3 - interest: creator
qui clogit choice pfemale2xfrau $maineffects 													 mathintxcreator carexcreator 												  																																																												[pw=w_t13_std], group(id_ind) or
	matrix E3max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker 				  			  mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E3min = e(b)
	
* 4 - interest: helper
qui clogit choice pfemale2xfrau $maineffects 																				  mathintxhelper carexhelper 										  																																	 																						[pw=w_t13_std], group(id_ind) or
	matrix E4max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator  				 			 mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E4min = e(b)

* 5 - interest: persuader
qui clogit choice pfemale2xfrau $maineffects 																											 mathintxpersuader carexpersuader																															 																											[pw=w_t13_std], group(id_ind) or
	matrix E5max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper				   				  mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E5min = e(b)
	
* 6 - interest: organizer
qui clogit choice pfemale2xfrau $maineffects 																																  			  mathintxorganizer carexorganizer 																										 																							[pw=w_t13_std], group(id_ind) or
	matrix E6max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader 									apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E6min = e(b)
	
* 7 - essentialism: internalized total
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer																							 																							[pw=w_t13_std], group(id_ind) or
	matrix E7max = e(b)
qui clogit choice pfemale2xfrau $maineffects 																																											   apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E7min = e(b)
	
* 8 - gender norms: parents
qui clogit choice pfemale2xfrau $maineffects 																																  											   apfmeltxfrau																		 																									[pw=w_t13_std], group(id_ind) or
	matrix E8max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer  			apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau  sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E8min = e(b)	

* 9 - gender norms: peers
qui clogit choice pfemale2xfrau $maineffects 																																  															apfmpeerxfrau 															 																								[pw=w_t13_std], group(id_ind) or
	matrix E9max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau 			  mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E9min = e(b)	
	
* 10 - gender norms: total	
qui clogit choice pfemale2xfrau $maineffects 																																  											   apfmeltxfrau apfmpeerxfrau 																 																							[pw=w_t13_std], group(id_ind) or
	matrix E10max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer 							  mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau  sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E10min = e(b)	
	
* 11 - education: relative math grades
qui clogit choice pfemale2xfrau $maineffects 																																  																		  mathintxleist_md											 																								[pw=w_t13_std], group(id_ind) or
	matrix E11max = e(b) 
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau 				   intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E11min = e(b)	
	
* 12 - essentialism: total	
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md												 																							[pw=w_t13_std], group(id_ind) or
	matrix E12max = e(b)
qui clogit choice pfemale2xfrau $maineffects 																																																						   intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E12min = e(b)

* 13 - separate spheres: bread 1
qui clogit choice pfemale2xfrau $maineffects 																																  																						   intercptxbread 								  																							[pw=w_t13_std], group(id_ind) or
	matrix E13max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md 				  intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau  sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E13min = e(b)
	
* 14 - separate spheres: bread 2
qui clogit choice pfemale2xfrau $maineffects 																																  																							 			  intercptxbread2 									  																 		[pw=w_t13_std], group(id_ind) or
	matrix E14max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread 				  intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau  sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E14min = e(b)
	
* 15 - separate spheres: bread 3
qui clogit choice pfemale2xfrau $maineffects 																																  																														  intercptxbread4 intercptxbread4xfrau  																	[pw=w_t13_std], group(id_ind) or
	matrix E15max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2					 				   hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau  sdiscrimxfrau		[pw=w_t13_std], group(id_ind) or
	matrix E15min = e(b)

* 16 - separate spheres: bread total
qui clogit choice pfemale2xfrau $maineffects 																																  																						   intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau  																	[pw=w_t13_std], group(id_ind) or
	matrix E16max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md 					 												   hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E16min = e(b)	

* 17 - separate spheres: overwork 1
qui clogit choice pfemale2xfrau $maineffects 																																  																																							   hrsworkxflexi 									 					[pw=w_t13_std], group(id_ind) or
	matrix E17max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau  			  hrsworkxbread3 hrsworkxbread3xfrau sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E17min = e(b)	
	
* 18 - separate spheres: overwork 2
qui clogit choice pfemale2xfrau $maineffects 																																  																																											  hrsworkxbread3 hrsworkxbread3xfrau 					[pw=w_t13_std], group(id_ind) or
	matrix E18max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi 									 sdiscrimxfrau 		[pw=w_t13_std], group(id_ind) or
	matrix E18min = e(b)	
	
* 19 - separate spheres: overwork total
qui clogit choice pfemale2xfrau $maineffects 																																  																																							   hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau 					[pw=w_t13_std], group(id_ind) or
	matrix E19max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau  													sdiscrimxfrau 	[pw=w_t13_std], group(id_ind) or
	matrix E19min = e(b)	

* 20  - separate spheres: total	
qui clogit choice pfemale2xfrau $maineffects 																																  																						   intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau  				 	[pw=w_t13_std], group(id_ind) or
	matrix E20max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md  							 																							sdiscrimxfrau 	[pw=w_t13_std], group(id_ind) or
	matrix E20min = e(b)	

* 21 - discrimination	
qui clogit choice pfemale2xfrau $maineffects 																																  																																																					sdiscrimxfrau 	[pw=w_t13_std], group(id_ind) or
	matrix E21max = e(b)
qui clogit choice pfemale2xfrau $maineffects mathintxdoer carexdoer mathintxthinker carexthinker mathintxcreator carexcreator mathintxhelper carexhelper mathintxpersuader carexpersuader mathintxorganizer carexorganizer apfmeltxfrau apfmpeerxfrau mathintxleist_md intercptxbread intercptxbread2 intercptxbread4 intercptxbread4xfrau hrsworkxflexi hrsworkxbread3 hrsworkxbread3xfrau    				 	[pw=w_t13_std], group(id_ind) or
	matrix E21min = e(b)

/* results matrix for min max decomposition
	rows: models
	columns:
	1 - rownumber
	2 - baseline coefficient pfemale2xfrau
	3 - pfemale2xfrau when adding var
	4 - max% explained for horizontal segregation
	5 - saturated coefficient pfemale2xfrau
	6 - pfemale2xfrau when droping var
	7 - min %explained for horizontal segregation
*/
matrix decomphor = J($modnr , 7, .)
matrix rownames decomphor = 1_doer 2_thinker 3_creator 4_helper 5_persuader 6_organizer 7_int_total 8_norms_elt 9_norms_peer 10_norms_total ///
	11_mdnoten 12_essent_total 13_moneyxintercpt 14_careerxintercpt 15_traditxfrauxintercpt 16_breadtotal 17_flexixhrswork 18_dutiesxfrauxhrswork 19_hrsworktotal 20_sepsphe_total 21_discr
matrix colnames decomphor = 1_rownr 2_base_hori 3_coef_add_hori 4_maxexpl_hori  5_satu_hori  6_coef_drop_hori  7_minexpl_hori
	
*** compute percentage explained (as in Morgan et al 2013)
forvalues i = 1/$modnr {
	matrix decomphor[`i', 1] = `i'
	matrix decomphor[`i', 2] = exp(A[1,1])
	matrix decomphor[`i', 3] = exp(E`i'max[1,1])
	matrix decomphor[`i', 4] = ((decomphor[`i',2]-1)-(decomphor[`i',3]-1))/(decomphor[`i',2]-1)
	matrix decomphor[`i', 5] = exp(B[1,1])
	matrix decomphor[`i', 6] = exp(E`i'min[1,1])
	matrix decomphor[`i', 7] = -1*((decomphor[`i',5]-1)-(decomphor[`i',6]-1))/(decomphor[`i',2]-1)
	}

matrix list decomphor, format(%10.4f)
putexcel set "Output\robustness2_minmaxdecomposition.xlsx", replace
putexcel B2 = matrix(decomphor, names) using "Output\robustness2_minmaxdecomposition.xlsx", replace

*** END ***
log close
exit, clear
